result
Syntax:
<result [name="a-result"] [type="forward|redirect"]>a-view's-uri</result> <result [name="a-result"] type="error">error-code</result> <result [name="a-result"] type="error">error-code: error-message</result> <result [name="a-result"] type="done"/>
It specifies a result of an action definition. It must be placed under the action element, and an action definition could have one or multiple results.
The result consists of the name, the type, and the URI of the targeted view. The name, if any, is specified as the name attribute, while the URI of the view is specified as the inner text of the result element. For example,
<result name="success">/WEB-INF/hello/HelloWorld.jsp</result>
<result>/WEB-INF/foo/Foo.jsp</result><!-- the default view -->
<result name="success2" type="redirect">/somewhere/to/go</result>
<result name="notfound" type="error">404</result>
Attributes
name
[Optional] [Default: null]
It specifies the name of the result. The view specified in a result is used, if the result's name matches the return value of the execute method.
If the name attribute is omitted, it is the default result. In other words, the URI of the view is used if no other result is matched.
type
[Optional] [Allowed: forward, redirect, error, done] [Default: forward] [since 1.1.0]
It specifies the type of result. By default, it is foward
. If you prefer send-redirect (i.e., HttpServletResponse.sendRedirect
), you could specify the type as redirect
, and the URI must be an URL that the user is allowed to access, i.e., it can't be located in /WEB-INF
.
If a result represents an error, you could specify the type as error
, and put the error code in the element, such as
<result name="notfound" type="error">404</result>
<result name="gone" type="error">301: moved</result>
If the action generates the output directly to the response, you could specify the type as done
, then ZEST won't handle it further but returning the response directly.
Version History
Version | Date | Content |
---|---|---|
1.1.0 | June 2011 | Three new types, redirect, error and done, were introduced. |